package org.hxyjs.dao.impl;

import org.hxyjs.dao.ActivityprizesDao;
import org.hxyjs.entity.Activityprizes;
import org.hxyjs.entity.Activityprizes;
import org.hxyjs.entity.Activityprizes;
import org.hxyjs.mapper.ActivityprizesMapper;
import org.hxyjs.page.PageInfo;
import org.hxyjs.utils.GenNumTools;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("activityprizesDao")//一般实现类不会直接生成默认对象名 而是使用 接口的默认对象名
public class ActivityprizesDaoImpl implements ActivityprizesDao {
    @Resource //autowired 会装配能够直接扫描到的对象  resource spring容器运行的时候才找到需要的对象  注入
    private ActivityprizesMapper activityprizesMapper;
    public List<Activityprizes>  getAllActivityprizess() throws Exception{
        return activityprizesMapper.selectByExample(null);
    }

    @Override
    public Integer deleteActivityprizesByApno(String apno)  throws Exception{
        return activityprizesMapper.deleteByPrimaryKey(apno);
    }

    @Override
    public Integer updateActivityprizesByApno(Activityprizes activityprizes)  throws Exception{
        return activityprizesMapper.updateByPrimaryKey(activityprizes);
    }

    @Override
    public Integer addActivityprizes(Activityprizes activityprizes)  throws Exception{
        activityprizes.setApno(initId());
        return activityprizesMapper.insertSelective(activityprizes);
    }
    public String initId(){
        String maxApno = activityprizesMapper.getMaxApno();
        return GenNumTools.initId("",3,maxApno);
    }
    @Override
    public List<Activityprizes>  getActivityprizesByPage(PageInfo pageInfo) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount = (int) activityprizesMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return activityprizesMapper.getActivityprizesByPage(map);
    }

}
